package com.liu.controls;

import java.util.List;

import com.liu.common.MyActivity;
import com.liu.controls.LockPatternView.Cell;
import com.liu.controls.LockPatternView.OnPatternListener;
import com.liu.keeppwd.R;

import android.os.Bundle;
import android.content.Intent;
import android.view.KeyEvent;
import android.widget.TextView;

public class LockPatternActivity extends MyActivity {
	LockPatternView lpv;
	public static int Su = 301;
	public static int Fa = 302;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lock_pattern);
		Intent in = getIntent();
		String title = in.getStringExtra("title");
		((TextView) findViewById(R.id.tv_title)).setText(title);
		lpv = (LockPatternView) findViewById(R.id.lpv);
		lpv.setOnPatternListener(new OnPatternListener() {

			@Override
			public void onPatternStart() {
			}

			@Override
			public void onPatternDetected(List<Cell> pattern) {
				String ss = "";
				for (int i = 0; i < pattern.size(); i++) {
					int x = pattern.get(i).getRow() * 3
							+ pattern.get(i).getColumn();
					ss += x;
				}
				Intent in=new Intent();
				in.putExtra("res", ss);
				LockPatternActivity.this.setResult(Su, in);
				LockPatternActivity.this.finish();
			}

			@Override
			public void onPatternCleared() {
			}

			@Override
			public void onPatternCellAdded(List<Cell> pattern) {
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			LockPatternActivity.this.setResult(Fa, null);
			LockPatternActivity.this.finish();
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

}
